var wxManager = require("wxManager");

cc.Class({
    extends: cc.Component,

    properties: {
       storyString: {
            type: cc.RichText,
            default: null
       },
	   
	    tips: {
            type: cc.Label,
            default: null
       },
	  
    },

    // LIFE-CYCLE CALLBACKS:

     onLoad () {
		 
		 this.wxmanager = new wxManager();
		
		this.wxmanager.showWxAd();
		 
		 this.story = "很久很久以前,华夏大地诸侯割据,战争不断,民不聊生,有一个年轻人立志要还天下太平,他的名字叫刘备......   ".split("");
		 
		 //console.log(this.story);
		 
		 this.index = 0;
		 
		 this.storyrealstring = "";
		 
		 this.storyString.string = "";
		 
		 this.calindex = 0;
		 
		 this.calmax = 5;
		 
		 this.stop = 0;
		 
		 this.loaded = 0;
		 
		 this.tips.node.runAction(cc.repeatForever(cc.sequence([cc.fadeOut(1),cc.fadeIn(1)])));
		 
			this.node.on(cc.Node.EventType.TOUCH_END, function(){
				
				this.stop=0;
				this.loaded=1;
				cc.director.loadScene('index');
				
			}, this);
		},

	update (dt) {
				
		if(this.stop==0){
			
			if(this.calindex<this.calmax){
				this.calindex++;
			}else{
				this.calindex = 0;
			
				if(this.index<this.story.length){
					this.storyrealstring+= this.story[this.index];
					this.storyString.string = this.storyrealstring;
					this.index++;
				}else{
					this.stop = 1;
				}
			}
		}else{
			if(!this.loaded){
				this.loaded=1;
				this.node.runAction(cc.sequence([cc.fadeIn(1),cc.callFunc(function () {
					cc.director.loadScene('index');
				}, this)]));
			}
			
			
		}
				
	},
});
